// @ts-nocheck
import 'lib-flexible';
import React, { useState } from 'react';
import jwtDecode from 'jwt-decode';
import './writeReview.less';
import '@/pages/golobo.less';
import { Rate } from 'antd-mobile';
import { NavBar, Input, Button } from 'react-vant';
import { history, useLocation } from 'umi';
import server from '@/utlis/server';
export default function writeReview() {
  let location = useLocation();
  const [Ratevalue, setValue] = useState(0);
  const [Ratevaluea, setValuea] = useState('');
  const [Ratezi, setziValue] = useState('你推荐这场演出吗');
  const setRatevalue = (e) => {
    if (e == 0) {
      setziValue('你推荐这场演出吗');
    } else if (e == 0.5) {
      setziValue('非常糟糕');
    } else if (e == 1) {
      setziValue('有些糟糕');
    } else if (e == 1.5) {
      setziValue('较差,不推荐');
    } else if (e == 2) {
      setziValue('不推荐');
    } else if (e == 2.5) {
      setziValue('一般般,不看也行');
    } else if (e == 3) {
      setziValue('一般般,看看也行');
    } else if (e == 3.5) {
      setziValue('还可以');
    } else if (e == 4) {
      setziValue('比较好,值得一看');
    } else if (e == 4.5) {
      setziValue('很不错,非常推荐');
    } else if (e == 1.5) {
      setziValue('棒极了,极力推荐');
    }
    setValue(e);
  };
  let sendoo = async () => {
    let token = localStorage.getItem('token');
    if (token) {
      let user = jwtDecode(token)._doc;
      let form = {
        user_id: user._id,
        per_id: location.state.state._id,
        context: Ratevaluea,
        num: Ratevalue,
      };
      // console.log(form);

      let { data } = await server.post('/yancup/addp', form);
      history.push({
        pathname: '/showevaluate',
        state: {
          state: location.state.state,
        },
      });
    }
  };
  return (
    <div style={{ padding: '0 0.3rem' }}>
      <div className="wR-navbar">
        <NavBar
          onClickLeft={() =>
            history.push({
              pathname: '/showevaluate',
              state: {
                state: location.state.state,
              },
            })
          }
        />
      </div>
      <div className="wR-rate">
        <h3>{Ratezi}</h3>
        <Rate defaultValue={Ratevalue} allowHalf onChange={setRatevalue} />
      </div>
      <hr style={{ marginTop: '0.4rem' }} />
      <div className="wR-input">
        <Input.TextArea
          placeholder="大家都问现场怎么样,场馆交通方便吗?"
          value={Ratevaluea}
          onChange={(val) => {
            setValuea(val);
          }}
          showWordLimit={({ currentCount }) => (
            <span>已经输入{currentCount}个字啦 ✍️</span>
          )}
        />
      </div>
      <div className="wR-fabu">
        <Button
          round
          type="info"
          disabled={Ratevaluea === '' ? true : false}
          onClick={() => {
            sendoo();
          }}
          color="linear-gradient(to right, #ff6034, #ee0a24)"
        >
          立即发布
        </Button>
      </div>
    </div>
  );
}
